package com.example.ch13appbar

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.main_menu,menu)
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        showMessage("fsfsdfwefsdfsdlfsdfksjk")

        when(item?.itemId){
            R.id.menuFile ->{
                showMessage("文件菜单")
                return true
            }
            R.id.menuEdit ->{
                showMessage("内容编辑")
                return true
            }
            R.id.menuHelp ->{
                showMessage("查看帮助")
                return true
            }
            R.id.menuExit ->{
                showMessage("退出应用")
                return true
            }
            else -> {
                return false
            }
        }



    }

    private fun showMessage(msg:String){
        Snackbar.make(root_layout,msg, Snackbar.LENGTH_LONG).show()

    }
}
